package xupt.se.ttms.view.studio;



import java.awt.Color;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.w3c.dom.css.ElementCSSInlineStyle;

import xupt.se.ttms.model.Customer;
import xupt.se.ttms.model.Studio;
import xupt.se.ttms.service.CustomerSrv;
import xupt.se.ttms.service.StudioSrv;
import xupt.se.ttms.view.employee.Employee_MainUITmpl;
import xupt.se.ttms.view.tmpl.Login;

import java.awt.Color;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class StudioAddUI{

	public static JTextField b2;
	public static JTextField c2;
	public static JTextField d2;
	public static JTextField e2;
	public static JTextField f2;
	public static JFrame frame;
	public  StudioAddUI(String user)
	{
		frame = new JFrame();
		frame.setSize(850,500);
		frame.setTitle("增加演出厅");
		frame.setBounds(0, 0, 850, 500);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(false);
		frame.setLocationRelativeTo(null);
		ImageIcon icon=new ImageIcon("img/logo.png");
		JLabel x = new JLabel(icon);
		icon.setImage(icon.getImage().getScaledInstance(850,70,Image.SCALE_DEFAULT));
		JPanel a=new JPanel();
		a.setBackground(Color.decode("#FFe4c4"));
		a.setLayout(null);
		x.setBounds(0,0,850,70);
		a.add(x);
		frame.add(a);
		JLabel a1=new JLabel("增加演出厅");
		a1.setBounds(400,80,100,25);
		a.add(a1);
		JLabel b1=new JLabel("名称:");
		b1.setBounds(300,130,50,25);
		a.add(b1);
		b2=new JTextField();
		b2.setBounds(350,130,200,25);
		a.add(b2);
		JLabel c1=new JLabel("行数:");
		c1.setBounds(300,160,50,25);
		a.add(c1);
		c2=new JTextField();
		c2.setBounds(350,160,200,25);
		a.add(c2);
		JLabel d1=new JLabel("列数：");
		d1.setBounds(300,190,50,25);
		a.add(d1);
		d2=new JTextField();
		d2.setBounds(350,190,200,25);
		a.add(d2);
		JLabel e1=new JLabel("介绍：");
		e1.setBounds(300,220,50,25);
		a.add(e1);
		e2=new JTextField();
		e2.setBounds(350,220,200,25);
		a.add(e2);

		JButton enter=new JButton("确认添加");
		enter.setBounds(350,290,90,30);
		enter.setFocusPainted(false);
		enter.setMargin(new Insets(0,0,0,0));
		enter.setContentAreaFilled(false);
		enter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent Event) {
				String name=b2.getText();
				String row=c2.getText();
				String col=d2.getText();
				String intro=e2.getText();
			
				if(name.equals("")|| row.equals("")||col.equals(""))
				{
					JOptionPane.showConfirmDialog(null, "输入不能为空");
				}
				else
				{
					Studio studio=new Studio();
					studio.setName(name);
					studio.setRowCount(Integer.parseInt(row));
					studio.setColCount(Integer.parseInt(col));
					studio.setIntroduction(intro);
					studio.setSeatnumber(Integer.parseInt(row)*Integer.parseInt(col));
					
					
					StudioSrv studioSrv=new StudioSrv();
					
					try {
						boolean b=studioSrv.add(studio);
						if(Employee_MainUITmpl.jTable!=null)
						{
							Employee_MainUITmpl.jTable.updateUI();
						}
						//JOptionPane.showConfirmDialog(null, "添加成功");
						frame.dispose();
						Employee_MainUITmpl employee_MainUITmpl=new Employee_MainUITmpl(user);
					
					} catch (Exception e) {
						// TODO 自动生成的 catch 块
						e.printStackTrace();
					}
				}		
			}
		});
		a.add(enter);
		JButton enter1=new JButton("返回");
		enter1.setBounds(460,290,90,30);
		enter1.setFocusPainted(false);
		enter1.setMargin(new Insets(0,0,0,0));
		enter1.setContentAreaFilled(false);
		enter1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent Event) {
				frame.dispose();
				Employee_MainUITmpl employee_MainUITmpl=new Employee_MainUITmpl(user);
			}
		});
		a.add(enter1);
		frame.setVisible(true);
		frame.setLayout(null);
		
		
	}

}
